/*
 * Copyright (C) 2000-2005 Philips Electronics N.V.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or 
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file gnu_license.txt.  If not, write to
 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
 * 
 */
#include <stdio.h>
#include <front/error.h>
#include "fe_flags.h"
#include "init.h"
#include "ast.h"
#include "cfrontPrint.h"
#include "typing.h"
#include "type.h"
#include "gcc.h"
#include "semantics.h"

static Bool flag_nostdinc = FALSE;
static Bool list_incpaths = FALSE;
static Bool list_defines = FALSE;

fe_cli_flag cli_flags[] = {
  { "-h",        NULL,           fe_help_flag, DFLT_NAME, { "display help message" } },
  { "-nostdinc", &flag_nostdinc, NULL,         DFLT_NAME, { "Do not include from the standard include paths" } },
  { "-list-defines",  &list_defines, NULL,   DFLT_NAME,   { "list all #defines and #undefs on stderr" } },
  { "-list-incpaths", &list_incpaths, NULL,  DFLT_NAME,   { "list all (standard, implied, and -I) include paths on stderr" } },     
};

static int num_cli_flags = sizeof(cli_flags)/sizeof(*cli_flags);

static void
parse_flags (int argc, char **argv)
{
  fe_package="cfront";
  fe_register_flags (num_libcpp_flags, libcpp_flags);
  fe_register_flags (num_cfront_flags, cfront_flags);
  fe_register_flags (num_cli_flags, cli_flags);
  fe_flags_use_regexp ();
  argc=fe_parse_flags(argc,argv);
  if(argc>1) infile = argv[1];
}

int
main (int argc, char **argv)
{
  cfront_initialize ();
  parse_flags (argc, argv);
  if (!flag_nostdinc) cfront_stdclib_support (infile);
  gcc_extenstions ();
  if (list_incpaths) CPP_list_incpaths();
  if (cfront_Parse (infile)) {   
    if (list_defines) CPP_list_defines(); 
    cfront_give_types (cfront_root);
    egg_exit_on_errors ();
    check_semantics (cfront_root);
    egg_exit_on_errors ();
    Check_AST ();
    
    gcc_adjust_va_list (cfront_root);
    Print_cfront_cfront (cfront_root);
  }
  return NumErrors!=0;
}
